<?php


namespace App\Http\Controllers\Common;


use App\Http\Controllers\Controller;
use App\Models\Currency;
use App\Repositories\Callback;
use App\Repositories\Consumable;
use App\Repositories\Country;
use App\Repositories\Customer;
use App\Repositories\CustomerEnterprises;
use App\Repositories\Customs;
use App\Repositories\Express;
use App\Repositories\HsCode;
use App\Repositories\Package;
use App\Repositories\Unit;
use App\Repositories\User;

class SelectController extends Controller
{
    /**
     * @param Customer $customer
     * @return \Illuminate\Http\JsonResponse
     */
    public function customer(Customer $customer)
    {
        return $this->response(
            $customer->get(['id as code', 'name'])
        );
    }

    /**
     * @param Express $express
     * @return \Illuminate\Http\JsonResponse
     */
    public function express(Express $express)
    {
        return $this->response(
            $express->get(['id as code', 'name'])
        );
    }

    /**
     * @param Callback $callback
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function callback(Callback $callback)
    {
        return $this->response(
            $callback->get(['id as code', 'name'])
        );
    }

    /**
     * @param Unit $unit
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function unit(Unit $unit)
    {
        return $this->response(
            $unit->get(['code', 'name'])
        );
    }

    /**
     * @param HsCode $code
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function hsCode(HsCode $code)
    {
        return $this->response(
            $code->get(['code', 'code as name', 'name as remark', 'unit1', 'unit2', 'element'])
        );
    }

    /**
     * @param Country $country
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function country(Country $country)
    {
        return $this->response(
            $country->get(['code', 'name'])
        );
    }

    /**
     * @param Currency $currency
     * @return mixed
     * @author luffyzhao@vip.126.com
     */
    public function currency(Currency $currency){
        return $this->response(
            $currency->get(['code', 'name'])
        );
    }

    /**
     * @param Customs $customs
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function customs(Customs $customs)
    {
        return $this->response(
            $customs->get(['code', 'name'])
        );
    }

    /**
     * @param Consumable $consumable
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function consumable(Consumable $consumable)
    {
        return $this->response(
            $consumable->get(['id as code', 'name'])
        );
    }

    /**
     * @param Package $package
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function package(Package $package)
    {
        return $this->response(
            $package->get(['id as code', 'name'])
        );
    }

    /**
     * @param CustomerEnterprises $enterprises
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function enterprises(CustomerEnterprises $enterprises, $id)
    {
        return $this->response(
            $enterprises->select($id, ['id as code', 'name'])
        );
    }

    /**
     * @param User $user
     * @return \Illuminate\Http\JsonResponse
     * @author luffyzhao@vip.126.com
     */
    public function user(User $user){
        return $this->response(
            $user->get(['id as code', 'name'])
        );
    }
}
